package com.shop.shoppingmall.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shop.shoppingmall.entity.ShBanner;
import com.shop.shoppingmall.entity.ShUser;
import com.shop.shoppingmall.service.ShBannerService;
import com.shop.shoppingmall.util.api.vo.Result;
import org.springframework.web.bind.annotation.*;
import com.shop.shoppingmall.util.api.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (ShBanner)表控制层
 *
 * @author makejava
 * @since 2020-09-10 09:18:22
 */
@RestController
@RequestMapping("shBanner")
@CrossOrigin
public class ShBannerController {
    /**
     * 服务对象
     */
    @Resource
    private ShBannerService shBannerService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ShBanner selectOne(String id) {
        return this.shBannerService.queryById(id);
    }

    /**
     * 添加轮播图
     * @param jsonObject
     * @return
     */
    @PostMapping("insertBanner")
    public Result insertBanner(@RequestBody JSONObject jsonObject) {
        ShBanner shBanner = JSON.parseObject(jsonObject.toJSONString(), ShBanner.class);
        return shBannerService.insert(shBanner);

    }

    /**
     * 修改轮播图信息
     * @param jsonObject
     * @return
     */
    @PostMapping("updateBanner")
    public Result updateBanner(@RequestBody JSONObject jsonObject) {
        ShBanner shBanner = JSON.parseObject(jsonObject.toJSONString(), ShBanner.class);
        return shBannerService.update(shBanner);

    }

    /**
     * 删除轮播图
     * @param id
     * @return
     */
    @GetMapping("deleteByBanner")
    public Result deleteByBanner(@RequestParam("bannerId") String id) {
        return shBannerService.deleteById(id);
    }
    /**
     * 查询出所有轮播图信息
     * @return
     */
    @GetMapping("/selectBannerAll")
    public Result selectBannerAll(){
        return shBannerService.selectBannerAll();
    }

    /**
     * 点击轮播图跳转商品商铺的详情
     * @param id
     * @param bannerType
     * @return
     */
    @GetMapping("/selectBannerProductAndShop")
    public Result selectBannerProductAndShop(@RequestParam("id") String id, @RequestParam("bannerType") String bannerType){
        return shBannerService.selectBannerProductAndShop(id,bannerType);
    }

}